Imports DotNetPM.Business.Questionnaire

Partial Class Modules_Questionnaires_Controls_logNumber
    Inherits System.Web.UI.UserControl
    Implements UserControls.ILogicUC

    Dim _question As Question

    Public Property Logic() As String Implements DotNetPM.Business.Questionnaire.UserControls.ILogicUC.Logic
        Get
            Dim sb As New StringBuilder
            If compChoices.Type = ValidationDataType.Double Then
                sb.Append("2|")
            Else
                sb.Append("3|")
            End If
            sb.Append(ddlOperators.SelectedIndex)
            sb.Append("|")
            sb.Append(numChoices.Text)
            Return sb.ToString
        End Get
        Set(ByVal value As String)
            Dim val As String() = value.Split("|")
            ddlOperators.SelectedIndex = val(1)
            numChoices.Text = val(2)
            AdjustControls()
        End Set
    End Property

    Public Property Question() As Question Implements DotNetPM.Business.Questionnaire.UserControls.ILogicUC.Question
        Get
            Return _question
        End Get
        Set(ByVal value As Question)
            _question = value
        End Set
    End Property

    Public Sub Reset() Implements DotNetPM.Business.Questionnaire.UserControls.ILogicUC.Reset
        ddlOperators.SelectedIndex = -1
        numChoices.Text = String.Empty
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        AdjustControls()
    End Sub

    Private Sub AdjustControls()
        If ddlAnswer.SelectedIndex Then
            ddlOperators.Visible = True
            numChoices.Visible = True
            reqChoices.Visible = True
            compChoices.Visible = True
            Dim val As String() = Split(_question.Configuration, "||")
            If val(2) = "2" Then
                'Float
                compChoices.Type = ValidationDataType.Double
                compChoices.ErrorMessage = "Invalid value for float !"
            Else
                compChoices.Type = ValidationDataType.Integer
                compChoices.ErrorMessage = "Invalid value for integer !"
            End If
        Else
            ddlOperators.Visible = False
            numChoices.Visible = False
            reqChoices.Visible = False
            compChoices.Visible = False
        End If
    End Sub

End Class
